#! /usr/bin/env python

from game import *
from string import *

class PyBaseball:
  
  # Pretty self-explanitory
  def main(self,argv):
  
    whererun = "main"
   
    # Set up some defaults
    homename="Rockies"
    awayname="Giants"
  
    # Check argv for overwrites of defaults
    
    for arg in argv:
      if arg == "-cgi":
        whererun="cgi"
      split_args=split(arg)
      split_at_eq=split(split_args[0],"=") 
      if split_at_eq[0] == "hometeam":
        homename = split_at_eq[1]
      if split_at_eq[0] == "awayteam":
        awayname = split_at_eq[1]
    
    homefile="teams/"+lower(homename)+".txt"
    awayfile="teams/"+lower(awayname)+".txt"
  
    mygame = Game(whererun,homename,homefile,awayname,awayfile)
    mygame.start()
    mygame.play()
    mygame.end()
  
  # If this program is being called as an executable
  # (i.e. not imported), then execute 'main'
if __name__ == '__main__':
  thispybaseball=PyBaseball()  
  sys.exit(thispybaseball.main(sys.argv[1:]))
